package com.huamao.niceman.scrollviewpager.home.view;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.huamao.niceman.scrollviewpager.R;
import com.huamao.niceman.scrollviewpager.base.BaseActivity;
import com.huamao.niceman.scrollviewpager.base.BaseFragment;
import com.huamao.niceman.scrollviewpager.widget.MyIndicator;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by LuanXianSheng on 2017/6/14.
 */

public class HomeFragment extends Fragment {
    @BindView(R.id.home_tag)
    MyIndicator mIndicator;
    @BindView(R.id.home_viewpager)
    ViewPager mViewpager;
    private BaseActivity act;
    private FragmentPagerAdapter adapter ;
    private List<String> mTitle = Arrays.asList("关注","推荐","娱乐","搞笑","军事","周边","社会","国内","国际");
    private List<BaseFragment> mContent = new ArrayList<>() ;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        act = (BaseActivity) context;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_home, null);
        ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initView();
        initData();
    }

    private void initData() {
        for (String title:mTitle){
            ConstellationFragment fragment = new ConstellationFragment() ;
            mContent.add(fragment) ;
        }
        adapter = new FragmentPagerAdapter(act.getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return mContent.get(position);
            }
            @Override
            public int getCount() {
                return mContent.size();
            }

            //选择器中通过这个方法获取tag中的内容
            @Override
            public CharSequence getPageTitle(int position) {
                return mTitle.get(position);
            }
        };
        mViewpager.setAdapter(adapter);
        mIndicator.setViewPager(mViewpager,1);
    }

    private void initView() {

    }
}
